package com.wuda.util;

import java.util.Iterator;

import com.wuda.cfg.Configure;

/**
 * <p>
 * 句子分割器
 * </p>
 * 
 * @author wuda
 * @version JDK1.7
 * 
 */
public class SentenceSegment implements Iterator<String> {

	private char[] charArray = null;

	/**
	 * 当前已经检查到的下标
	 */
	private int currentIndex = 0;

	/**
	 * 生成句分隔器实例
	 * 
	 * @param input
	 *            需要分割成多个句子的文本
	 */
	public SentenceSegment(String input) {
		this.charArray = input.toCharArray();
	}

	@Override
	public boolean hasNext() {
		return currentIndex < charArray.length;
	}

	@Override
	public String next() {
		StringBuilder buffer = new StringBuilder();
		Character ch = null;
		while (currentIndex < charArray.length) {
			ch = charArray[currentIndex];
			if (Configure.PUNCTION.indexOf(ch) == -1) {
				buffer.append(ch);
				currentIndex++;
			} else {
				currentIndex++; // 丢掉当前这个标点符号
				break;
			}
		}
		return buffer.toString();
	}

	@Override
	public void remove() {
		// do nothing

	}
}
